﻿#region Copyrigth and License
/*==============================================================================
 *  Copyright (c) cndotnet.org Corporation.  All rights reserved.
 * ===============================================================================
 * This code and information is provided "as is" without warranty of any kind,
 * either expressed or implied, including but not limited to the implied warranties
 * of merchantability and fitness for a particular purpose.
 * ===============================================================================
 * Licensed under the GNU General Public License (GPL) v2
 * http://www.cndotnet.org/ezsocio
 * ==============================================================================*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CNdotnet.Ezsocio.ContactService
{
    public class ContractServiceUtil:IContractService {
        #region Fileds
        ContractType _ct;
        string _ts;
        string _sessionCookie;
        #endregion

        #region Constructors
        public ContractServiceUtil(ContractType ct) {
            _ct = ct;
        }
        public ContractServiceUtil(string ts, string sessionCookie) {
            _ct = ContractType.QQ;
            _ts = ts;
            _sessionCookie = sessionCookie;
        }
        #endregion

        #region Propertity

        #endregion

        #region Events

        #endregion

        #region Methods

        #endregion

        public UContractCollection GetContracts(string account,string pwd,string verifyCode) {
            UContractCollection ucc = new UContractCollection();
            switch (_ct) {
                case ContractType.Email:
                    {
                        var col = Email.EmailServiceManager.GetContracts(account, pwd);
                        foreach (var c in col) {
                            UContract uc = new UContract();
                            uc.Email = c.Email;
                            uc.Name = c.Name;
                            ucc.Add(uc);
                        }
                        break;
                    }
                case ContractType.QQ:
                    {
                        var col = new QQ.QQService(_ts).GetContracts(account, pwd, verifyCode, _sessionCookie);
                        foreach (var c in col) {
                            UContract uc = new UContract();
                            uc.Email = c.Email;
                            uc.Name = c.Name;
                            ucc.Add(uc);
                        }
                        break;
                    }
                case ContractType.Live: {
                        var col = LiveID.LiveIDService.GetLiveContracts();
                        foreach (var c in col) {
                            UContract uc = new UContract();
                            uc.Email = c.Emails.Address;
                            uc.Name = c.Profiles.DisplayName;
                            ucc.Add(uc);
                        }
                        break;
                    }
            }
            return ucc;
        }
    }
}
